#ifndef FLV_MESSAGE_H_
#define FLV_MESSAGE_H_

#include "./../amf_module/amf.h"
#include <cstdint>
#include <map>
#include <string>
#include <vector>

class FlvMessage
{
public:
    struct FlvHeader
    {
        std::string m_signature; // flv
        int         m_version;
        int         m_audio_flag;
        int         m_video_flag;
        int         m_data_offset;
    };
    struct FlvTag
    {
        int                  m_tag_type;
        int                  m_data_size;
        uint32_t             m_time_stamp; // time stamp and time stamp ext
        uint32_t             m_stream_id;
        std::vector<uint8_t> m_data;
    };
    struct FlvMetaData
    {
        AmfArray * m_object{nullptr};
        ~FlvMetaData()
        {
            if (m_object)
            {
                delete m_object;
                m_object = nullptr;
            }
        }
    };
public:
    FlvMessage();
    ~FlvMessage();
    void             FlvHeader(const FlvMessage::FlvHeader &flv_header);
    void             PushTag(FlvMessage::FlvTag & tag);
    struct FlvHeader GetFlvHeader();
    FlvTag *         GetFlvTagByIndex(int index);
    int              FlvTagCount() const;
    FlvMetaData    * GetMetaData();
    void             RemoveByIndex(int index);
    void             MetaData(AmfArray * object);
private:
    struct FlvHeader    m_header;
    struct FlvMetaData  m_metadata;
    std::vector<FlvTag> m_tag_vec;
};

#endif
